public class Solution_278 extends VersionControl {
    public int firstBadVersion(int n) {
        int left = 1, right = n;

        while(left < right) {
            int mid = left + (right - left) / 2;
            if (isBadVersion(mid)) {
                right = mid; // [left, mid]
            } else {
                left = mid + 1; // [mid + 1, right]
            }
            
        }
        // [left, right] left == right
        return left;
    }

    public static void main(String[] args) {
        int version = new Solution_278().firstBadVersion(5);
        System.out.println(version);
    }


}